import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 保养任务信息 */
export interface KeepTask {
  id: number // id
  waitId?: number // 待保养ID
  equipmentId?: number // 设备id
  startTime: string | Dayjs // 开始时间
  endTime: string | Dayjs // 结束时间
  reviewerId: string // 审核人ID
  reviewerName: string // 审核人名称
  itemId: number // 待保养大类ID
  itemSubId: string // 待保养明细ID
  itemSubComplete: string // 已完成的保养明细ID
  description: string // 补充说明
}

// 保养任务 API
export const KeepTaskApi = {
  // 查询保养任务分页
  getKeepTaskPage: async (params: any) => {
    return await request.get({ url: `/business/keep-task/page`, params })
  },

  // 查询维修任务统计
  getKeepTaskStatistics: async (params: any) => {
    return await request.get({ url: `/business/keep-task/statistics`, params })
  },

  // 查询保养任务详情
  getKeepTask: async (id: number) => {
    return await request.get({ url: `/business/keep-task/get?id=` + id })
  },

  // 新增保养任务
  createKeepTask: async (data: KeepTask) => {
    return await request.post({ url: `/business/keep-task/create`, data })
  },

  // 修改保养任务
  updateKeepTask: async (data: KeepTask) => {
    return await request.put({ url: `/business/keep-task/update`, data })
  },

  // 删除保养任务
  deleteKeepTask: async (id: number) => {
    return await request.delete({ url: `/business/keep-task/delete?id=` + id })
  },

  /** 批量删除保养任务 */
  deleteKeepTaskList: async (ids: number[]) => {
    return await request.delete({ url: `/business/keep-task/delete-list?ids=${ids.join(',')}` })
  },

  // 导出保养任务 Excel
  exportKeepTask: async (params) => {
    return await request.download({ url: `/business/keep-task/export-excel`, params })
  },

  //维护模块=========================

  // 查询保养任务分页
  getKeepTaskPageDamage: async (params: any) => {
    return await request.get({ url: `/Damage/keep-task/page`, params })
  },

  // 查询维修任务统计
  getKeepTaskStatisticsDamage: async (params: any) => {
    return await request.get({ url: `/Damage/keep-task/statistics`, params })
  },

  // 查询保养任务详情
  getKeepTaskDamage: async (id: number) => {
    return await request.get({ url: `/Damage/keep-task/get?id=` + id })
  },

  // 新增保养任务
  createKeepTaskDamage: async (data: KeepTask) => {
    return await request.post({ url: `/Damage/keep-task/create`, data })
  },

  // 修改保养任务
  updateKeepTaskDamage: async (data: KeepTask) => {
    return await request.put({ url: `/Damage/keep-task/update`, data })
  },

  // 删除保养任务
  deleteKeepTaskDamage: async (id: number) => {
    return await request.delete({ url: `/Damage/keep-task/delete?id=` + id })
  },

  /** 批量删除保养任务 */
  deleteKeepTaskListDamage: async (ids: number[]) => {
    return await request.delete({ url: `/Damage/keep-task/delete-list?ids=${ids.join(',')}` })
  },

  // 导出保养任务 Excel
  exportKeepTaskDamage: async (params) => {
    return await request.download({ url: `/Damage/keep-task/export-excel`, params })
  }
}
